package com.xbongbong.paas.service.stage.impl;

import com.xbongbong.paas.domain.entity.PaasStageEntity;
import com.xbongbong.paas.domain.entity.StageLogEntity;
import com.xbongbong.paas.service.stage.StageLogHandle;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.entity.ClueStageEntity;
import com.xbongbong.saas.domain.entity.ClueStageLogEntity;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.model.ClueStageLogModel;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author 李少杰
 * @version v1.0.0
 * @date 2021/11/23 14:19
 */
@Service("clueStageLogHandle")
public class ClueStageLogHandle implements StageLogHandle {

    @Resource
    private ClueStageLogModel clueStageLogModel;

    @Override
    public Integer businessType() {
        return XbbRefTypeEnum.CLUE.getCode();
    }

    @Override
    public StageLogEntity get(Long stageLogId, String corpid) throws XbbException {
        return clueStageLogModel.getByKey(stageLogId, corpid);
    }

    @Override
    public Integer deleteBatch(List<StageLogEntity> stageLogEntityList, String corpid) throws XbbException {
        return clueStageLogModel.deleteBatch(stageLogEntityList, corpid);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return clueStageLogModel.getEntitysCount(param);
    }

    @Override
    public List<StageLogEntity> findEntitys(Map<String, Object> params) {
        List<ClueStageLogEntity> entitys = clueStageLogModel.findEntitys(params);
        return Arrays.asList(entitys.toArray(new StageLogEntity[0]));
    }

    @Override
    public void save(StageLogEntity stageLogEntity) {
        ClueStageLogEntity ClueStageLogEntity = new ClueStageLogEntity();
        BeanUtils.copyProperties(stageLogEntity, ClueStageLogEntity);
        clueStageLogModel.save(ClueStageLogEntity);
    }

    @Override
    public StageLogEntity getNowStageLog(Long dataId, String corpid, Long formId) {
        return clueStageLogModel.getNowStageLog(dataId, corpid, formId);
    }

    @Override
    public void insertBatchStageLogList(List<StageLogEntity> stageLogList) {
        clueStageLogModel.insertBatch((List<ClueStageLogEntity>)(Object)stageLogList);
    }

    @Override
    public Integer deleteByStageProcessIdAndDataIdIn(List<Long> dataIdIn, String corpid, Long formId, Long stageProcessId, Long stageId) {
        return clueStageLogModel.deleteByStageProcessIdAndDataIdIn(dataIdIn, corpid, formId, stageProcessId, stageId);
    }

    @Override
    public Long getAvgStayTime(String corpid, Long stageProcessId, Long stageId) {
        return clueStageLogModel.getAvgStayTime(corpid, stageProcessId, stageId);
    }

    @Override
    public List<Long> findUsedStageProcessId(String corpid, Long formId, List<Long> stageProcessIdIn) {
        return clueStageLogModel.findUsedStageProcessId(corpid, formId, stageProcessIdIn);
    }
}
